<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('shop/index')}">店铺列表</a></li>
        <li class="active"><a href="#">编辑店铺</a></li>
    </ul>
    <form class="form-horizontal js-ajax-form margin-top-20" role="form" action="{:url('shop/edit')}"
          method="post">
          <input type="hidden" name="id" value="{$info['id']}">
        <fieldset>
            <div class="tabbable">
                <div class="tab-content">
                    <div class="tab-pane active" id="A">
                        <div class="form-group">
                            <label for="input-site-name" class="col-sm-2 control-label">店铺名称</label>
                            <div class="col-md-6 col-sm-10">
                                <input type="text" class="form-control" name="name"
                                       value="{$info['name']}">
                            </div>
                        </div>
                        <div class="form-group">
                          <label for="input-site-name" class="col-sm-2 control-label">审核状态</label>
                          <div class="col-md-3 col-sm-5">
                              <select name="status" class="form-control">
                                  <option <if condition="$info['status'] eq 1"> selected </if> value="1">--审核通过--</option>
                                  <option <if condition="$info['status'] eq 2"> selected </if> value="2">--未审核--</option>
                                  <option <if condition="$info['status'] eq 3"> selected </if> value="3">--审核拒绝--</option>
                              </select>
                          </div>
                      </div>
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">获取经度</label>
                            <div class="col-sm-2">
                                <input type="text" name="lng" id="lng" class="form-control" value="{$info['lng']}">
                            </div>
                            <label for="inputEmail3" class="col-sm-2 control-label">获取纬度</label>
                            <div class="col-sm-2">
                                <input type="text" name="lat" id="lat" class="form-control" value="{$info['lat']}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">地址</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" name='address' id='sever_add' value="{$info['address']}">
                            </div>
                            <!-- <div class="col-sm-2">
                                <input type='button' value='点击显示地图获取地址经纬度' id='open'>
                            </div> -->
                        </div>
                        <div class="form-group" id="map_new" >
                            <label for="inputEmail3" class="col-sm-2 control-label">地图选取</label>
                            <div class="col-sm-8" style="height:500px;">
                                <div id='allmap' style='width: 100%; height:100%; position: absolute;'></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" style="width:150px;" class="btn btn-primary">
                                    {:lang('SAVE')}
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>

</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=Oh5n7HIgPqoEoAQxFe5byC1GYSNmMXLX"></script>
<script type="text/javascript">
    function validate() {
      var sever_add = document.getElementsByName('sever_add')[0].value;
      if (isNull(sever_add)) {
        alert('请选择地址');
        return false;
      }
      return true;
    }
    //判断是否是空
    function isNull(a) {
      return (a == '' || typeof(a) == 'undefined' || a == null) ? true : false;
    }
    // document.getElementById('open').onclick = function () {
    //   if (document.getElementById('map_new').style.display == 'none') {
    //     document.getElementById('map_new').style.display = 'block';
    //   } else {
    //     document.getElementById('map_new').style.display = 'none';
    //   }
    // }
    var map = new BMap.Map("allmap");
    var geoc = new BMap.Geocoder();  //地址解析对象
    var markersArray = [];
    var geolocation = new BMap.Geolocation();
    var point = new BMap.Point(116.331398, 39.897445);
    map.centerAndZoom(point, 12); // 中心点
    

    geolocation.getCurrentPosition(function (r) {
      if (this.getStatus() == BMAP_STATUS_SUCCESS) {
        var mk = new BMap.Marker(r.point);
        map.addOverlay(mk);
        map.panTo(r.point);
        map.enableScrollWheelZoom(true);
      }
      else {
        alert('failed' + this.getStatus());
      }
    }, {enableHighAccuracy: true})
    map.addEventListener("click", showInfo);
    //清除标识
    function clearOverlays() {
      if (markersArray) {
        for (i in markersArray) {
          map.removeOverlay(markersArray[i])
        }
      }
    }
    //地图上标注
    function addMarker(point) {
      var marker = new BMap.Marker(point);
      markersArray.push(marker);
      clearOverlays();
      map.addOverlay(marker);
    }
    //点击地图时间处理
    function showInfo(e) {
      document.getElementById('lng').value = e.point.lng;
      document.getElementById('lat').value = e.point.lat;
      geoc.getLocation(e.point, function (rs) {
        var addComp = rs.addressComponents;
        var address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
        if (confirm("确定要地址是" + address + "?")) {
        //   document.getElementById('map_new').style.display = 'none';
          document.getElementById('sever_add').value = address;
        }
      });
      addMarker(e.point);
    }
</script>
</body>
</html>
